<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class Classify extends BaseModel
{
    use SoftDeletes;

    //框架软删除

    const TP = ['J', 'K'];
    const JD = [1, 2, 3, 4, 5];
    const VUE_USED_ZY = ['ZH', 'XL', 'LJ', 'Q', 'HQ', 'S', 'Z', 'J', 'L', 'DC', 'SH', 'TX', 'XH', 'D', 'DH', 'XX', 'F', 'HB', 'DM', 'ZY', 'RF', 'LL', 'JL', 'P', 'QG', 'FZ', '空'];
    const VUE_USED_EARLY_ZY = ['GL', 'ZTB', 'HT', 'JT', 'GG', 'SHB', 'YD', 'AZ', 'JG', '空'];

    const ZY = [
        'ZH' => '综合',
        'XL' => '线路',
        'LJ' => '路基',
        'Q'  => '桥梁',
        'HQ' => '涵渠',
        'S'  => '隧道',
        'Z'  => '站场',
        'J'  => '机务',
        'L'  => '车辆',
        'DC' => '动车',
        'SH' => '给(排)水',
        'TX' => '通信',
        'XH' => '信号',
        'D'  => '电力',
        'DH' => '电化',
        'XX' => '信息',
        'F'  => '房建',
        'HB' => '环保',
        'DM' => '地亩',
        'ZY' => '专用线',
        'RF' => '人防',
        'LL' => '履历簿',
        'JL' => '监理',
        'P'  => '平检',
        'QG' => '三电迁改',
        'FZ' => '防灾',
    ];

    /**
     * 前期文件代码
     */
    const EARLY_ZY = [
        'GL'  => '综合文件',
        'ZTB' => '招投标',
        'HT'  => '合同',
        'JT'  => '计划与投资',
        'GG'  => '工程管理',
        'SHB' => '环境保护与水土保持',
        'YD'  => '铁路用地',
        'AZ'  => '安全质量管理和监督',
        'JG'  => '竣工验收',
    ];

    protected $guarded = [
        'id'
    ];

    /*循环修改的字段*/
    public $fields = [
        'template_id',
    ];

    /**
     * 检索从分类目录复制到项目分类目录表的数据
     * @return HasMany
     */
    function projectClassifies(): HasMany
    {
        return $this->hasMany(ProjectClassify::class);
    }

    /**
     *
     * @return BelongsTo
     */
    function classifyTemplate(): BelongsTo
    {
        return $this->belongsTo(ClassifyTemplate::class);
    }

    /**
     * 创建者
     * @return BelongsTo
     */
    public function user()
    {
        return $this->belongsTo(User::class, 'creator_id', 'id');
    }
}
